package com.dzxcqmxm.servlet.user;

import com.dzxcqmxm.Dao.UserDao;
import com.dzxcqmxm.Dao.impl.UserDaoImpl;
import com.dzxcqmxm.JB.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Payboi
 * @create 2022/6/2-22:00
 * @FileName updateUserServlet
 * @Description
 */
@WebServlet("/updateUserServlet")
public class updateUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserDao userDao = new UserDaoImpl();
        User user = new User();
        //修改
        String UserName = request.getParameter("UserName");

//            customerDao.delCustomer(Integer.parseInt(id));


        user.setUserName(new String(request.getParameter("UserName" ).getBytes("iso-8859-1"),"UTF-8"));
        user.setUserPwd(new String(request.getParameter("UserPwd" ).getBytes("iso-8859-1"),"UTF-8"));

        try {
            /**
             * 执行了更新语句
             */
            userDao.updateUser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }

        response.sendRedirect("/dzxc/indexUserServlet");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
